<template>
  <div>
    <div class="header_search_nav search_form">
      <div class="ipt_left">
        <el-form ref="queryForm" :model="queryParams" label-width="80px">
          <el-row>
            <el-col :span="5">
              <el-form-item prop="storeIdIn" label="转入门店">
                <el-select
                  class="select_ipt"
                  v-model="queryParams.storeIdIn"
                  placeholder="请选择门店"
                  filterable
                  @change="changePage"
                >
                  <el-option
                    v-for="item in $store.state.user.stores"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item prop="storeIdOut" label="转出门店">
                <el-select
                  class="select_ipt"
                  v-model="queryParams.storeIdOut"
                  placeholder="请选择门店"
                  filterable
                  @change="changePage"
                >
                  <el-option
                    v-for="item in $store.state.user.stores"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <div class="pay_ipt">
                <el-form-item label="客户" prop="memberId">
                  <el-select
                    class="w-160"
                    v-model="queryParams.memberId"
                    placeholder="请选择"
                    filterable
                    remote
                    :loading="Memberloading"
                    reserve-keyword
                    :remote-method="remoteMethod"
                    @change="changePage"
                  >
                    <el-option
                      v-for="item in tableList"
                      :key="item.id"
                      :label="item.name + '-' + item.mobile"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="6">
              {{ queryParams.time }}

              <div class="timebox">
                <el-form-item label="日期时间" prop="date">
                  <timer ref="timer" :timer.sync="queryParams.date"></timer>
                </el-form-item>
              </div>

              <!-- <el-date-picker
                  v-model="queryParams.time"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker> -->
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="btn_right">
        <button class="btn1" @click="handleQuery">筛选</button>
        <button class="btn2" @click="resetQuery">重置</button>
      </div>
    </div>

    <div class="table_card">
      <!-- 上部分 title -->
      <div class="table_card_top">
        <span class="solid_left"></span>
        <div class="table_card_title">转卡列表</div>
        <div class="op_right">
          <el-button
            @click="handleExport"
            :loading="exportLoading"
            class="repeat"
            v-hasPermi="['customer:card-transfer:page:admin:exl']"
            >导出</el-button
          >
        </div>
      </div>

      <div class="table_list">
        <el-table
          :data="TransferList"
          stripe
          style="width: 100%"
          v-loading="loading"
        >
          <el-table-column
            prop="memberInName"
            label="转入会员名称"
            :show-overflow-tooltip="true"
            width="170px"
          >
          </el-table-column>
          <el-table-column
            prop="cardIdInName"
            label="转入会员卡名称"
            width="200px"
          >
          </el-table-column>
          <el-table-column prop="cardNumberIn" label="转入会员卡编号">
            <template slot-scope="scope">
              <span
                style="color: #005cc8; cursor: pointer"
                @click="CheckMemberIn(scope.row)"
                >{{ scope.row.cardNumberIn }}</span
              >
            </template>
          </el-table-column>
          <el-table-column prop="memberOutName" label="转出会员名称">
          </el-table-column>
          <el-table-column
            prop="cardIdOutName"
            label="转出会员卡名称"
            width="200px"
          >
          </el-table-column>
          <el-table-column prop="cardNumberOut" label="转出会员卡编号">
            <template slot-scope="scope">
              <span
                style="color: #005cc8; cursor: pointer"
                @click="CheckMemberOut(scope.row)"
                >{{ scope.row.cardNumberOut }}</span
              >
            </template>
          </el-table-column>
          <el-table-column prop="principal" label="本金"> </el-table-column>
          <el-table-column prop="giveMoney" label="赠送金"> </el-table-column>
          <el-table-column prop="extraMoney" label="额外赠送金" width="110px">
          </el-table-column>
          <el-table-column prop="createTime" label="转账时间">
          </el-table-column>
        </el-table>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>

    <client-info ref="clientInfo"></client-info>
  </div>
</template>

<script>
import { getTransferPage, getClientList } from "@/api/business/client";
import { exlStoreProfit } from "@/api/bpm/excle";
import timer from "@/components/getTime/timer";
import ClientInfo from "../../../components/ClientInfo/clientInfo.vue";
export default {
  name: "Storeadmintransfercard",
  components: { timer, ClientInfo },
  data() {
    return {
      TransferList: [],
      loading: false,
      Memberloading: false,
      seachUserClientTimeout: false,
      queryTypeOptions: [],

      value: "",
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        storeIdIn: "",
        storeIdOut: "",
        memberId: "", // 渠道类型标识
        startTime: "", //开始时间 yyyy-MM-dd HH:mm:ss
        endTime: "", // 结束时间,
        date: [],
        // keyword: "",
      },
      total: 0,
      tableList: [],
      exportLoading: false,
    };
  },

  mounted() {},

  created() {
    this.getList();
    this.getLists();
    // this.getStorelist();
  },

  methods: {
    changePage() {
      this.getList();
    },
    // 查看会员详情
    CheckMemberIn(row) {
      let obj = JSON.parse(JSON.stringify(row));
      obj.id = row.memberInId;
      this.$refs.clientInfo.MemberUserInfo(obj);
    },
    CheckMemberOut(row) {
      let obj = JSON.parse(JSON.stringify(row));
      obj.id = row.memberOutId;
      this.$refs.clientInfo.MemberUserInfo(obj);
    },
    handleExport() {
      this.$modal
        .confirm("是否确认导出报表数据?")
        .then(() => {
          this.exportLoading = true;
          let queryParams = JSON.parse(JSON.stringify(this.queryParams));

          if (!!this.queryParams.date) {
            queryParams.startTime = this.queryParams.date[0];
            queryParams.endTime = this.queryParams.date[1];
          }
          delete queryParams.date;
          return exlStoreProfit(queryParams);
        })
        .then((response) => {
          this.$download.excel(response, "转卡列表");
          this.exportLoading = false;
        })
        .catch(() => {
          this.exportLoading = false;
        });
    },
    remoteMethod(query) {
      if (query !== "") {
        clearTimeout(this.seachUserClientTimeout);
        this.seachUserClientTimeout = setTimeout(() => {
          this.getLists(query);
        }, 500);
      } else {
        this.options = [];
      }
    },

    // 会员列表 所有
    getLists(query) {
      console.log(query);
      this.Memberloading = true;
      getClientList({
        pageNo: 1,
        pageSize: 10,
        keyword: query,
      })
        .then((res) => {
          console.log(res);
          this.Memberloading = false;
          const { code, data } = res;
          if (code === 0) {
            this.tableList = data.list;
          }
        })
        .catch((err) => {
          this.Memberloading = false;
        });
    },
    // 筛选
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
      this.getLists();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetFormData("queryForm");
      this.handleQuery();
    },

    // 表单重置
    resetFormData(formName) {
      console.log(this.$refs[formName]);
      this.$refs[formName].resetFields();
    },

    // 转卡列表
    getList() {
      this.loading = true;
      const query = JSON.parse(JSON.stringify(this.queryParams));

      if (!!query.date) {
        query.startTime = this.queryParams.date[0];
        query.endTime = this.queryParams.date[1];
        query.date = [];
      }

      getTransferPage(query)
        .then((res) => {
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.TransferList = data.list;
            this.total = data.total;
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.goodTop {
  width: 100%;
  height: 48px;
  background: #ffffff;
  display: flex;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.6);
  line-height: 48px;
  padding-left: 16px;
  .good_list {
    margin-right: 32px;
  }

  .good_active {
    color: #0052d9;
    border-bottom: 1px solid #0052d9;
  }
}

.w-200 {
  width: 200px;
  background: #ffffff;
  border-radius: 4px;
}

.client_name {
  font-size: 14px;
  font-weight: 400;
  color: #0052d9;
}

.give {
  height: 40px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
  margin-top: 40px;
  line-height: 40px;
}

.el-form-item {
  margin-bottom: 20px;
}

.recharge_form {
  padding: 10px 24px;
}

.memberName {
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
}
.el_row_item {
  margin-bottom: 10px;
}
.el_row_date {
  margin-top: 20px;
}
.el_row_reason {
  margin-top: 10px;
}

.el_row_date {
  .el-form-item {
    margin-bottom: 0px;
  }
}

.Order_box {
  display: flex;
  margin-left: -50px;
  .select_ipt {
    width: 130px;
    margin-right: 10px;
  }
}

.pay_ipt {
  margin-left: 50px;
}

.order_ipt {
  margin-left: -120px;
}
</style>
